#include <windows.h>
#include <commctrl.h>
#include <WindowsX.h>
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

#include "AccountList.h"
#include "Http.h"
#include "resource.h"

#pragma comment(lib, "comctl32.lib")

AccountList* al=new AccountList("AccountList.txt");

void InitWnd(HWND hWnd)
{
	al->InsertAccountInfoToTreeView(hWnd);
}

void LoginGame(HWND hWnd)
{
	string account=al->GetSelectedAccount(hWnd);
	if (account=="")
	{
		return;
	}
	string password=al->GetSelectedPassword();
	string host=al->GetSelectedHost();
	string serverid=al->GetSelectedServerId();
	Http* http=new Http(host,serverid,account,password);
}

int CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	WORD low;
	WORD high;
	switch (uMsg)
	{
	case WM_INITDIALOG:
		InitWnd(hwndDlg);
		break;
	case WM_COMMAND:
		switch(wParam)
		{
		case IDOK:
			LoginGame(hwndDlg);
			break;
		default:
			break;
		}
		break;
	case WM_CLOSE:
#ifndef DEBUG
		exit(0);
#endif
		break;
	default:
		break;
	}
	return 0;
}

int CALLBACK WinMain(__in HINSTANCE hInstance,__in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine,__in int nShowCmd)
{
#ifdef DEBUG
	AllocConsole();
	FILE *stream;
	freopen_s(&stream,"conin$", "r+t", stdin);
	freopen_s(&stream,"conout$", "w+t", stdout);
	freopen_s(&stream,"conout$", "w+t", stderr);
#endif
	InitCommonControls();
	DialogBoxParamA(hInstance,(LPCSTR)IDD_DIALOG1,0,DialogProc,0);
}